package com.example.lay.ui;

import android.app.Activity;
import android.media.Image;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by cuilei on 2014/12/9.
 */
public class MySimpleAdapter extends Activity {
    private String[] names = {
            "小明",
            "李白"
    };
    private String[] descs = {
            "学生",
            "诗人"
    };
    private int[] imageIds = {
            R.drawable.xiaoming,
            R.drawable.libai
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
        Map<String, Object> listItem = null;
        for (int i = 0; i < names.length; i++) {
            listItem = new HashMap<String, Object>();
            listItem.put("header", imageIds[i]);
            listItem.put("personName", names[i]);
            listItem.put("desc", descs[i]);
            listItems.add(listItem);
        }
        SimpleAdapter adapter = new
                SimpleAdapter(this, listItems,
                R.layout.simple_item, new String[]{"header", "personName", "desc"},
                new int[]{R.id.header, R.id.name, R.id.desc});
        ((ListView)findViewById(R.id.lv_list)).setAdapter(adapter);
    }
}
